package com.sesame.feign;


import com.sesame.user.bean.User;
import kim.sesame.common.result.ApiResult;
import kim.sesame.framework.web.response.ResponseFactory;
import org.springframework.cloud.openfeign.FeignClient;
import org.springframework.stereotype.Component;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;

import java.util.List;


@FeignClient(name = FeignServiceTx2.APP_NAME, fallback = FeignServiceTx2Hystrix.class)
public interface FeignServiceTx2 {

    String APP_NAME = "DISTRIBUTED-TX-5-EXAMPLE-CH2-SERVICE";
    String SERVICE_NAME = "";

    @GetMapping(SERVICE_NAME + "/user/list")
    Response<List<User>> getList();

    @RequestMapping(value = SERVICE_NAME + "/user/save")
    Response save(@RequestParam("id") String id, @RequestParam("updateUser") String updateUser);

}

@Component
class FeignServiceTx2Hystrix implements FeignServiceTx2 {

    @Override
    public ApiResult<List<User>> getList() {
        return ResponseFactory.feignException("getList");
    }

    @Override
    public ApiResult save(String id, String value) {
        return ResponseFactory.feignException("update2");
    }
}